
package com.applabs.dnd.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DNDMeDbaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "DndApp.db";

    private static final int DATABASE_VERSION = 1;

    private static final String DNDPROFILE_TABLE_NAME = "DndProfiles";

    private static final String DNDSCHEDULE_TABLE_NAME = "DndSchedules";

    private static final String TAG = "DNDMeDbaseHelper";

    DNDMeDbaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // create table to store user names
        db.execSQL("CREATE TABLE '" + DNDPROFILE_TABLE_NAME + "'" + "('" + DNDMeColumns.DPROFILE_ID
                + "' INTEGER PRIMARY KEY AUTOINCREMENT,'" + DNDMeColumns.DPROFILE_NAME
                + "' TEXT NOT NULL, '" + DNDMeColumns.DPROFILE_ISWHITELIST
                + "' INTEGER DEFAULT 0, '" + DNDMeColumns.DPROFILE_CALLRULETYPE
                + "' INTEGER DEFAULT 0, '" + DNDMeColumns.DPROFILE_CALLREJTYPE
                + "' INTEGER DEFAULT 0, '" + DNDMeColumns.DPROFILE_NUMCALLSTODISABLE
                + "' INTEGER DEFAULT 5, " + DNDMeColumns.DPROFILE_REJMSG + "' TEXT NOT NULL)");

        db.execSQL("CREATE TABLE '" + DNDSCHEDULE_TABLE_NAME + "'" + "('" + DNDMeColumns.DSCHED_ID
                + "' INTEGER PRIMARY KEY AUTOINCREMENT,'" + DNDMeColumns.DSCHED_NAME
                + "' TEXT NOT NULL, '" + DNDMeColumns.DSCHED_TIME_FROM + "' TEXT NOT NULL, '"
                + DNDMeColumns.DSCHED_TIME_TO + "' TEXT NOT NULL, '" + DNDMeColumns.DPROFILE_ID
                + "' INTEGER)");
        Log.d(TAG, "onCreate: success ");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "onUpgrade: success ");
        db.execSQL("DROP TABLE IF EXISTS " + DNDPROFILE_TABLE_NAME);
        onCreate(db);
    }
}
